package com.cc.controller;

import com.cc.pojo.Emp;
import com.cc.pojo.EmpQueryParam;
import com.cc.pojo.PageResult;
import com.cc.pojo.Result;
import com.cc.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;

    @GetMapping
    public Result list(EmpQueryParam param){
        log.info("员工列表查询");
        PageResult<Emp> pageResult =empService.page(param);
        return  Result.success(pageResult);
    }

    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("员工列表删除");
        empService.delect(ids);
        return  Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Emp emp){
        log.info("员工新增 {} "+ emp);
        empService.add(emp);
        return  Result.success();
    }
    @GetMapping("/{id}")
    public Result getID(@PathVariable Integer id){
        log.info("查询部门: id={}", id);
        Emp emp=empService.getID(id);
        return Result.success(emp);
    }
    @PutMapping
    public Result update(@RequestBody Emp emp){
        log.info("员工修改 {} "+ emp);
        empService.update(emp);
        return  Result.success();
    }

    @GetMapping("/list")
    public  Result findAll(){
        log.info("查询所有员工{}");
        List<Emp> empList=empService.findAll();
        return  Result.success(empList);
    }
}
